package cn.laixueit;

import cn.laixueit.dao.StudentDao;
import cn.laixueit.dao.StudentDaoImpl;
import cn.laixueit.dao.StudentDaoImpl2;
import cn.laixueit.pojo.Student;
import cn.laixueit.service.StudentServiceImpl;
import cn.laixueit.servlet.StudentServlet;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Arrays;
import java.util.Date;

public class Demo {

    @Test
    public void t(){
        /* 上下文对象 */
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        Student student = context.getBean("student", Student.class);
        System.out.println(student);
    }

    @Test
    public void t2(){
        /* 上下文对象 */
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        Student student = context.getBean("student2", Student.class);
        System.out.println(student);
    }

    @Test
    public void t3(){
        /* 上下文对象 */
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        Student student = context.getBean("student3", Student.class);
        System.out.println(student);
    }

    @Test
    public void t4(){
        /* 上下文对象 */
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        Date now = context.getBean("now", Date.class);
        System.out.println(now);
    }

    @After
    public void after(){

    }
    ClassPathXmlApplicationContext context = null;
    @Before
    public void before(){
        context = new ClassPathXmlApplicationContext("applicationContext.xml");
    }

    @Test
    public void t5(){
        Student student = context.getBean("student4", Student.class);
        /*System.out.println(Arrays.toString(student.getNums()));
        System.out.println(student.getNums().length);
        System.out.println(student.getNames().size());
        System.out.println(student.getMap());*/
    }

    @Test
    public void t6(){
//      StudentDao studentDao = new StudentDaoImpl();
        /*
        * spring : 动态代理
        * */
        StudentDao studentDao = context.getBean("studentDao", StudentDao.class);
        studentDao.save();
    }


    @Test
    public void t7(){
        StudentServiceImpl serviceImpl = context.getBean("studentServiceImpl", StudentServiceImpl.class);
        serviceImpl.save();
    }
    @Test
    public void t8(){
        StudentDaoImpl2 studentDaoImpl2 = context.getBean("studentDaoImpl2", StudentDaoImpl2.class);
        studentDaoImpl2.save();
    }

    @Test
    public void t9(){
        StudentServlet studentServlet = context.getBean("studentServlet", StudentServlet.class);
        studentServlet.save();

    }

}
